// 封装用户相关请求
import request from '@/utils/request.js'
// import store from '@/store'

/**
 * 登录
 * @param { Object } data { mobile: '', code: ''}
 */
export const login = data => {
  return request({
    method: 'POST',
    url: '/v1_0/authorizations',
    data
  })
}

/**
 * 获取短信验证码
 * @param {*} mobile 手机号
 * @returns
 */
export const sendSms = mobile => {
  return request({
    method: 'GET',
    url: `/v1_0/sms/codes/${mobile}`
  })
}

/**
 * 加载用户个人信息
 * @returns
 */
export const getUserInfo = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user'
    // headers: {
    //   Authorization: `Bearer ${store.state.user.token}`
    // }
  })
}

/**
 * 获取用户频道列表
 * @returns
 */
export const getUserChannels = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/channels'
  })
}

/**
 * 取消关注
 * @param {*} id 用户id
 * @returns promise
 */
export const deleteUserFollow = id => {
  return request({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + id
  })
}

/**
 * 关注
 * @param {*} id 用户id
 * @returns promise
 */
export const addUserFollow = id => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target: id
    }
  })
}

/**
 * 获取用户个人资料
 * @returns
 */
export const getUserprofile = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/profile'
  })
}

/**
 * 修改用户信息
 * @param {Object} data name? gender? birthday?
 * @returns
 */
export const setUserprofile = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data
  })
}

/**
 * 保存头像
 * @param {*} data 表单数据对象
 * @returns promise
 */
export const setUserAvatar = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data
  })
}
